using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SharpObjects.XpathToObjects
{
    public abstract class PathElement
    {
        public enum ePathElementType
        {
            Root,
            AnyPlace,
            AnyName,
            Object,
            Axis
        }

        public string  Text { get; set; }
        public abstract ePathElementType ElementType { get; }

        protected PathElement(string text)
        {
            this.Text = text;
        }

        public override string ToString()
        {
            return this.Text;
        }

        public override bool Equals(object obj)
        {
            if(obj == null)
            {
                return false;
            }

            PathElement pathElement = (PathElement) obj;

            return this.ElementType == pathElement.ElementType && this.Text == pathElement.Text;
        }

        public override int GetHashCode()
        {
            return this.Text.GetHashCode();
        }

        public static bool ArePathsEqual(List<PathElement> path1, List<PathElement> path2 )
        {
            if(path1 == null || path2 == null)
            {
                return false;
            }

            if(path1.Count != path2.Count)
            {
                return false;
            }

            //for (int k = 0; k < path1.Count; k++)
            //{
            //    if (!path1[k].Equals(path2[k]))
            //    {
            //        return false;
            //    }
            //}

            return !path1.Where((pathElement, k) => !pathElement.Equals(path2[k])).Any();
        }
    }
}